package com.treetao.union.db.service.impl;

import com.treetao.union.db.model.MallPService;
import com.treetao.union.db.mapper.MallPServiceMapper;
import com.treetao.union.db.service.MallPServiceService;
import com.treetao.union.db.service.MallPSkuServiceService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 服务保障 服务实现类
 * </p>
 *
 * @author Dev.M
 * @since 2020-04-11
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class MallPServiceServiceImpl extends ServiceImpl<MallPServiceMapper, MallPService> implements MallPServiceService {
	@Autowired
	private MallPSkuServiceService mallPSkuServiceService;
	
	@Override
	public List<MallPService> getServices(Long skuId) {
		List<com.treetao.union.db.model.MallPSkuService> listServiceRef  = mallPSkuServiceService.getSkuServices(skuId);
		if(listServiceRef!=null) {
			List<Long> serviceIds = listServiceRef.stream().map(item -> item.getRefServiceId()).collect(Collectors.toList());
			if(serviceIds==null || serviceIds.size()==0) {
				return null;
			}
			QueryWrapper<MallPService> q = new QueryWrapper<MallPService>();
			q.eq("del_flag", false);
			q.in("id", serviceIds);
			return list(q);
		}
		return new ArrayList<MallPService>();
	}

}
